package com.lc.SlidingPaneUnit;


import android.app.Activity;
import android.content.Intent;
import android.view.ActionMode.Callback;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;

import com.example.japaneseapp.R;
import com.example.japaneseapp.TestNewWordActivity;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.lc.adapter.ListUnitAdapter;
import com.lc.japaneseapp.FlashCardNewWordActivity;

public class UnitFragment extends SlidingMenu{
	Activity activity;
	private ListView listNameUnit;
	private ListUnitAdapter listUnitAdapter;
	private Button btnCardFlash, btnTestNewWord;
	private int idUnit = 0;

	public UnitFragment(Activity activity) {
		super(activity);
		setFadeDegree(0.35f);
		this.activity = activity;
		setMenu(R.layout.leftside_unit_pane);
		
		attachToActivity(activity, SLIDING_CONTENT);
		listNameUnit = (ListView) findViewById(R.id.listUnit);
		listUnitAdapter = new ListUnitAdapter(activity, R.layout.item_unit_layout);
		listNameUnit.setAdapter(listUnitAdapter);
		listNameUnit.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				idUnit = position;
				( (UnitChangeListener) UnitFragment.this.activity).onChangeUnit(position);
			}
		});
		btnCardFlash = (Button) findViewById(R.id.buttonCard);
		btnCardFlash.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(UnitFragment.this.activity,
						FlashCardNewWordActivity.class);
				intent.putExtra("ID_UNIT", idUnit);
				startActionMode((Callback) intent);
			}
		});
		btnTestNewWord = (Button) findViewById(R.id.buttonTest);
		btnTestNewWord.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(UnitFragment.this.activity,
						TestNewWordActivity.class);
				intent.putExtra("ID_UNIT", idUnit);
				startActionMode((Callback) intent);
			}
		});
	}



	
	public interface UnitChangeListener{
		public void onChangeUnit(int idUnit);
	}
	
	public int NameUnit[] = {R.raw.unit1, R.raw.unit2,R.raw.unit3,R.raw.unit4,R.raw.unit5,
			R.raw.unit6, R.raw.unit7,R.raw.unit8,R.raw.unit9,R.raw.unit10,
			R.raw.unit11, R.raw.unit12,R.raw.unit13,R.raw.unit14,R.raw.unit15,
			R.raw.unit16, R.raw.unit17,R.raw.unit18,R.raw.unit19};
	
	
}
